//
//  GRModifyNickNameViewController.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/28.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRModifyNickNameViewController.h"
#import "LFTextField.h"

@interface GRModifyNickNameViewController () <LFTextFieldDelegate>

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLayout;

@property (weak, nonatomic) IBOutlet LFTextField *nickNameTF;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;

@end

@implementation GRModifyNickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if (IS_IPHONEX) {
        _topLayout.constant  = 88;
    }
    self.nickNameTF.text     = self.nickname;
    self.nickNameTF.delegate = self;
}

-(void)textField:(UITextField *)textField textDidChange:(NSString *)text {
    if (textField.text.length > 0 && !self.sureBtn.enabled) {
        [self changeSureButtonStatus:YES];
    }else {
        [self changeSureButtonStatus:NO];
    }
}

- (void)changeSureButtonStatus:(BOOL)status {
    self.sureBtn.enabled         = status;
    self.sureBtn.backgroundColor = status ? KGMTHEM_COLOR : KGMBACKGROUND_COLOR;
    [self.sureBtn setTitleColor:status ? KGMBLACK_COLOR : KGMGRAY_COLOR forState:UIControlStateNormal];
}

- (IBAction)didClickSureButton:(UIButton *)sender {
    NSDictionary *paramer = @{@"type"  : @"nickname",
                              @"value" :self.nickNameTF.text
                              };
    [GRPersonAction updateUserProfile:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            if (self.completion) {
                self.completion();
            }
            [self.navigationController popViewControllerAnimated:YES];
        }else {
            [GRHUD showMessage:[error errorMsg] atView:self.view];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
